package com.union.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.Components;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

    private final String HEADER = "Authorization";

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title(GlobalConfig.getName())
                        .description(GlobalConfig.getName() + "接口文档")
                        .version("版本号:" + GlobalConfig.getVersion())
                        .contact(new Contact()
                                .name("union")
                                .url("http://www.union.com/")
                                .email("1358620113@qq.com")))
                .components(new Components()
                        .addSecuritySchemes(HEADER, new SecurityScheme()
                                .type(SecurityScheme.Type.APIKEY)
                                .in(SecurityScheme.In.HEADER)
                                .name(HEADER)))
                .addSecurityItem(new SecurityRequirement().addList(HEADER));
    }
}
